//! Network system calls
//! SPDX-License-Identifier: MPL-2.0

const std = @import("std");
const SyscallReturn = @import("../return.zig").SyscallReturn;
const SyscallError = @import("../error.zig").SyscallError;
const Context = @import("../context.zig").Context;
const Fd = @import("../context.zig").Fd;
const VirtAddr = @import("../context.zig").VirtAddr;

/// Socket domains
pub const SocketDomain = enum(i32) {
    AF_UNIX = 1,
    AF_INET = 2,
    AF_INET6 = 10,
    _,
};

/// Socket types
pub const SocketType = enum(i32) {
    SOCK_STREAM = 1,
    SOCK_DGRAM = 2,
    SOCK_RAW = 3,
    SOCK_SEQPACKET = 5,
    _,
};

/// Create a socket
pub fn sys_socket(domain: i32, socket_type: i32, protocol: i32, ctx: *Context) SyscallReturn {
    _ = domain;
    _ = socket_type;
    _ = protocol;
    _ = ctx;
    // TODO: Implement socket creation
    return SyscallReturn.error_return(SyscallError.ENOSYS);
}

/// Connect to a socket
pub fn sys_connect(sockfd: Fd, addr: VirtAddr, addrlen: u32, ctx: *Context) SyscallReturn {
    _ = sockfd;
    _ = addr;
    _ = addrlen;
    _ = ctx;
    // TODO: Implement socket connection
    return SyscallReturn.error_return(SyscallError.ENOSYS);
}

/// Accept a connection
pub fn sys_accept(sockfd: Fd, addr: VirtAddr, addrlen: VirtAddr, ctx: *Context) SyscallReturn {
    _ = sockfd;
    _ = addr;
    _ = addrlen;
    _ = ctx;
    // TODO: Implement accept
    return SyscallReturn.error_return(SyscallError.ENOSYS);
}

/// Send data to a socket
pub fn sys_sendto(
    sockfd: Fd,
    buf: VirtAddr,
    len: usize,
    flags: i32,
    dest_addr: VirtAddr,
    addrlen: u32,
    ctx: *Context,
) SyscallReturn {
    _ = sockfd;
    _ = buf;
    _ = len;
    _ = flags;
    _ = dest_addr;
    _ = addrlen;
    _ = ctx;
    // TODO: Implement sendto
    return SyscallReturn.error_return(SyscallError.ENOSYS);
}

/// Receive data from a socket
pub fn sys_recvfrom(
    sockfd: Fd,
    buf: VirtAddr,
    len: usize,
    flags: i32,
    src_addr: VirtAddr,
    addrlen: VirtAddr,
    ctx: *Context,
) SyscallReturn {
    _ = sockfd;
    _ = buf;
    _ = len;
    _ = flags;
    _ = src_addr;
    _ = addrlen;
    _ = ctx;
    // TODO: Implement recvfrom
    return SyscallReturn.error_return(SyscallError.ENOSYS);
}

/// Bind a socket to an address
pub fn sys_bind(sockfd: Fd, addr: VirtAddr, addrlen: u32, ctx: *Context) SyscallReturn {
    _ = sockfd;
    _ = addr;
    _ = addrlen;
    _ = ctx;
    // TODO: Implement bind
    return SyscallReturn.error_return(SyscallError.ENOSYS);
}

/// Listen for connections
pub fn sys_listen(sockfd: Fd, backlog: i32, ctx: *Context) SyscallReturn {
    _ = sockfd;
    _ = backlog;
    _ = ctx;
    // TODO: Implement listen
    return SyscallReturn.error_return(SyscallError.ENOSYS);
}